import {Component, OnInit} from '@angular/core';
import {UserPublicInfo} from "@shared/models/UserInfo";
import {api} from "@core/service/config/api";
import {Router} from "@angular/router";
import {SharePageService, UserListData} from "@core/service/page/SharePageService";

@Component({
  selector: 'bby-user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.scss']
})
export class UserListComponent implements OnInit {
  pageData:UserListData
  avatarUrl=api.getAvatar
  pageLimit=12;
  constructor(
    private router:Router,
    public pageService:SharePageService
  ) {
    this.pageData=pageService.userListPageData
    // this.loadList(1)
  }

  ngOnInit(): void {

  }
  openDisk(user:UserPublicInfo) {
    this.router.navigate(['/share/disk/'+user.userId]);
  }

  pageIndexChange() {
    let param = this.pageService.openParam
    if (param?.search){
      console.log('search')
      this.router.navigate([this.pageService.openUrl],{
        queryParams:{
          page:this.pageData.listPage,
          search:param.search
        }
      })
    }else {
      console.log('ssss',this.pageData.listPage)
      this.pageService.loadUserRoots(this.pageData.listPage)
    }
  }

  isLastPage() {
    return this.pageData.list.length<this.pageLimit
  }
}

